package com.yhgm.utils;

import com.google.gson.Gson;
import com.yhgm.entity.ImageSearch;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.common.xcontent.XContentType;

import java.io.IOException;
import java.util.Date;

public class Main {
    public static void main(String[] args) {
//        ImageSearch imageSearch=new ImageSearch();
//        imageSearch.setId("1");
//        imageSearch.setPatientIdNumber("513822019283...");
//        imageSearch.setShootingEquipment("CT");
//        imageSearch.setImageOrgan("肝脏");
//        imageSearch.setAcquisitionTime("2012-12-12T12:12:12");
//        imageSearch.setImageFormat("DICOM");
//        imageSearch.setResult("左上部有癌症病变....");
//        imageSearch.setDistrict("南充，四川");
//        imageSearch.setAge(56);
//        imageSearch.setPath("/gz/demo/images1.zip");
//        System.out.println(new Gson().toJson(imageSearch));
//        IndexRequest req=new IndexRequest("image_search").id(imageSearch.getId());
//        req.source(new Gson().toJson(imageSearch), XContentType.JSON);
//        try {
//            ESClient esClient=new ESClient();
//            //DateConverter.convertToElasticsearchFormat()
//            esClient.getClient().index(req, RequestOptions.DEFAULT);
//        } catch (IOException e) {
//            //todo:add sys-logs
//            e.printStackTrace();
//        }

//        //2.query
        ESClient esClient=new ESClient();
        GetRequest getRequest=new GetRequest("image_search","1");
        GetResponse getResponse= null;
        try {
            getResponse = esClient.getClient().get(getRequest, RequestOptions.DEFAULT);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println(getResponse.getSourceAsString());
    }
}
